<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    okText="确认"
    :class="editType =='detail'?'pic-preview':''"
    :cancelText="editType =='detail'?'关闭':'取消'">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <h5 class="modalH5">需求方</h5>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="需求方">
              <a-input disabled v-decorator="['Interactive_Company_CompanyName', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="联系人">
              <a-input disabled  v-decorator="['DemandUser_UserName', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="职务">
              <a-input disabled v-decorator="['DemandUser_Job', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="电话">
              <a-input disabled v-decorator="['DemandUser_Phone', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item
              :labelCol="labelColMax"
              :wrapperCol="wrapperColMax"
              label="需求标签">
              <a-input disabled v-decorator="['Interactive_DemandTag', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item
              :labelCol="labelColMax"
              :wrapperCol="wrapperColMax"
              label="简单描述">
              <a-input type="textarea" disabled v-decorator="['Interactive_DemandDescription', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item
              :labelCol="labelColMax"
              :wrapperCol="wrapperColMax"
              label="详细描述">
              <a-input type="textarea" disabled v-decorator="['Interactive_DemandDetail', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <h5 class="modalH5">供应方</h5>
          </a-col>
          
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="供应方">
              <a-input disabled v-decorator="['Supplier_CompanyName', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="联系人">
              <a-input disabled v-decorator="['SupplierUser_UserName', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="职务">
              <a-input disabled v-decorator="['SupplierUser_Job', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="电话">
              <a-input disabled v-decorator="['SupplierUser_Phone', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="应付令额">
              <a-input disabled  v-decorator="['PayableLin', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="券抵扣额">
              <a-input disabled v-decorator="['CouponLin', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="实付令额">
              <a-input disabled v-decorator="['PaidLin', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="付款日期">
              <a-date-picker show-time disabled v-decorator="['PayDate', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="状态">
              <a-input disabled v-decorator="['InteractiveStatus_Value', {}]" />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="成交日期">
              <a-date-picker show-time disabled v-decorator="['TradeDate', {}]" />
            </a-form-item>
          </a-col>
		    </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "BaseInfoModal",
    watch:{
      visible(newVal,oldVal){
        if(newVal){
          this.editType = sessionStorage.getItem('editType');
        }
      }
    },
    data () {
      return {
        editType:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 8 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 14 },
        },
        labelColMax: {
          xs: { span: 24 },
          sm: { span: 4 },
        },
        wrapperColMax: {
          xs: { span: 24 },
          sm: { span: 19 },
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        ItemType:{rules: [{ required: true, message: '请输入选择币种类型!' }]},
        ItemName:{rules: [{ required: true, message: '请输入物品名!' }]},
        Amt:{rules: [{ required: true, message: '请输入额度!' }]},
        value:{rules: [{ required: true, message: '请输入分类值!' }]},
        updatebyid:{rules: [{ required: true, message: '请输入最近更新人!' }]},
        ts:{rules: [{ required: true, message: '请输入最近更新日期!' }]},
        datastatus:{rules: [{ required: true, message: '请输入状态 Y-有效 N-无效!' }]},
        },
        ItemTypeData:[],
        url: {
          add: "/businessInteractive/add",
          edit: "/businessInteractive/update",
          baseList:'/baseInfo/queryRows'
        },
      }
    },
    created () {
      this.getBaseData();
    },
    methods: {
      getBaseData(){
        this.$http.postAction(this.url.baseList,{pageNo:1,pageSize:100,selectFields:[],conditions:[{
              "field":"TypeCode",
              "operator":"=",
              "value":'ItemType'
            }]}).then((res)=>{
          if(res.status == 1){
            this.ItemTypeData = res.data.rows;
          }
        })
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'Supplier_CompanyName','Discount','PayableLin','CouponLin','PaidLin','InteractiveStatus_Value','Interactive_DemandDetail','Interactive_DemandDescription','Interactive_DemandTag','Interactive_Company_CompanyName','DemandUser_UserName','DemandUser_Job','DemandUser_Phone','SupplierUser_UserName','SupplierUser_Job','SupplierUser_Phone'))
		  //时间格式化
          this.form.setFieldsValue({TradeDate:this.model.TradeDate?moment(this.model.TradeDate,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({PayDate:this.model.PayDate?moment(this.model.PayDate,'YYYY-MM-DD HH:mm:ss'):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.BusinessInteractiveId){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.TradeDate = formData.TradeDate?formData.TradeDate.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.PayDate = formData.PayDate?formData.PayDate.format('YYYY-MM-DD HH:mm:ss'):null;
            console.log(formData)
            this.$http.postAction(httpurl,formData,method).then((res)=>{
              if(res.status == 1){
                that.$message.success('提交成功');
                if(method == 'post'){
                  this.form.resetFields();
                  this.model = {};
                }else{
                  that.close();
                }
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              // that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>